package com.baitu.websokettest.util;
import com.baitu.websokettest.entity.Message;
import com.baitu.websokettest.entity.User;
import com.baitu.websokettest.vo.MessageVO;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;

import java.util.Set;

/*
 * 系统消息格式：{"isSystem":true,"fromName":null,"message","你好"}
 * 推送给某一个的消息格式：{"isSystem":true,"fromName":"张三","message",["李四","王五"]}
 */
public class MessageUtils {
    public static String getMessage(boolean isSystem,Integer fromId, Set<User> message) {
        try {
            MessageVO message1 = new MessageVO();
            message1.setSystem(isSystem);
            message1.setSetUser(message);
            if(fromId != null) {
                message1.setFromId(fromId);
            }
            ObjectMapper mapper = new ObjectMapper();

            return mapper.writeValueAsString(message1);
        } catch (JsonProcessingException e) {
            e.printStackTrace();
        }
        return null;
    }
}
